{include file="public/top" /}

<body>
<div class="x-body">
    <form class="layui-form">
        <input type="hidden" name="id" value="{$data.id}">
        <div class="layui-form-item">

            <div class="layui-form-item">
                <label class="layui-form-label" style="margin: 20px 0 0 0;"> <span class="x-red">*</span>微信二维码</label>
                <label for="test1">
                    <span id="imgg1">
                    <img style="height: 80px;width: 120px;margin: 0 10px 0 0;cursor:pointer;" src="{$data.facebook}">
                    </span>
                    <span>请上传微信二维码</span>
                </label>
                <span id="t1"></span>
                <button type="button" style="margin: 5px 0 0 0;display: none" class="layui-btn layui-btn-small" id="test1">
                    <i class="layui-icon">&#xe67c;</i>上传图片
                </button>
            </div>
            <br>
        </div>

        <div class="layui-form-item">
            <button type="button"  class="layui-btn layui-btn-normal" lay-filter="add" lay-submit="" style="margin-left: 100px">提交</button>
        </div>
    </form>
</div>
<script>

    var addurl = '/admin/setup/social';
    var imgupUrl = '/admin/index/imgUp';
    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form
            ,layer = layui.layer;

        //自定义验证规则
        form.verify({
            pass: [/(.+){6,12}$/, '密码必须6到12位']
            ,repass: function(value){
                if($('#L_pass').val()!=$('#L_repass').val()){
                    return '两次密码不一致';
                }
            }
        });

        //监听提交
        form.on('submit(add)', function(data){
            $.post(addurl, data.field,function(res) {
                var success = JSON.parse(res);
                if(success.code===200){
                    layer.msg(success.msg, {
                        time: 1000, //不自动关闭
                        icon:6,
                        end:function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        }
                    });
                    return false;
                }else {
                    layer.msg(success.msg)
                }


            });

        });
        layui.use('upload', function(){
            var upload = layui.upload;
            //执行实例
            var uploadInst = upload.render({
                elem: '#test1' //绑定元素
                ,url: imgupUrl //上传接口
                ,done: function(res){
                    var  option = '<img style="height: 80px;width: 120px;margin: 0 10px 0 0;cursor:pointer;" src="'+res.data+'">';
                    $('#imgg1').html(option);
                    var addBox = '<input type="hidden" name="facebook" value="'+res.data+'">';
                    document.getElementById('t1').innerHTML += addBox;
                }
                ,error: function(){
                    //请求异常回调
                }
            });

        });
    });

</script>
</body>

</html>